#ifndef _TEXTURE_H_
#define _TEXTURE_H_

#include <stdlib.h>
#include "glm/glm.hpp"

#define VARIANCE 32768

using namespace glm;

class NoiseGen {
private:
    float **n;
    int width, height;

public:
    NoiseGen(int w, int h) {
        width = w;
        height = h;

        srand(0);
        n = (float **) malloc(sizeof(float *) * width);
        for (int i = 0; i < width; i++) {
            n[i] = (float *) malloc(sizeof(float) * height);
            for (int j = 0; j < height; j++) {
                n[i][j] = ((float) (rand() % VARIANCE)) / VARIANCE;
            }
        }
    }
/*
    ~NoiseGen() {
        for (int i = 0; i < width; i++) {
            free(noise[i]);
        }

        free(noise);
    }
*/
    float sample(int x, int y);
    float smoothNoise(float x, float y);
    float turbulence(float x, float y, float size);
    
    float noise(float x, float y) {
        return turbulence(x, y, 256.0);
    }
    
    ~NoiseGen() {
        for (int i = 0; i < width; i++) {
            free(n[i]);
        }

        free(n);
    }
};

extern vec3 perlin1(float x, float y, vec3 pos, NoiseGen *n);
extern vec3 perlin2(float x, float y, vec3 pos, NoiseGen *n);
extern vec3 perlin3(float x, float y, vec3 pos, NoiseGen *n);

#endif
